Binary Bitwise Operators

Visualizing `&`, `|`, and `^`.

Bitwise AND (`&`)

The **Bitwise AND** operator returns `1` in each bit position for which the corresponding bits of both operands are `1`. Otherwise, it returns `0`.

5 & 1; // 1 (binary 0101 & 0001 -> 0001)

Bitwise AND (`&`)

Binary A:

Binary B:

Result Binary:

Result (Decimal):


Bitwise OR (`|`)

The **Bitwise OR** operator returns `1` in each bit position for which the corresponding bits of either or both operands are `1`. Otherwise, it returns `0`.

5 | 1; // 5 (binary 0101 | 0001 -> 0101)

Bitwise OR (`|`)

Binary A:

Binary B:

Result Binary:

Result (Decimal):


Bitwise XOR (`^`)

The **Bitwise XOR** (exclusive OR) operator returns `1` in each bit position for which the corresponding bits of the two operands are different. Otherwise, it returns `0`.

5 ^ 1; // 4 (binary 0101 ^ 0001 -> 0100)

Bitwise XOR (`^`)

Binary A:

Binary B:

Result Binary:

Result (Decimal):